package com.base.self.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.base.result.ResponseResult;
import com.base.result.ResponseResultUtils;
import com.base.self.entity.MerchantCollectionImage;
import com.base.self.service.IMerchantCollectionImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("admin")
@Api(tags = "商家二维码相关接口")
public class MerchantCollectionImageController {

    @Autowired
    private IMerchantCollectionImageService merchantCollectionImageService;

    @PostMapping("/merchantCollectionImage/load")
    @ApiOperation("获取商家二维码")
    @ResponseBody
    public ResponseResult load(){
        MerchantCollectionImage merchantCollectionImage = merchantCollectionImageService.getOne(new QueryWrapper<>());
        return ResponseResultUtils.getResponseResultS("查询成功",merchantCollectionImage);
    }
    @PostMapping("/merchantCollectionImage/update")
    @ApiOperation("修改商家二维码")
    @ResponseBody
    public ResponseResult update(@Validated MerchantCollectionImage image){
        MerchantCollectionImage merchantCollectionImage = merchantCollectionImageService.getOne(new QueryWrapper<>());
        if (null == merchantCollectionImage){
            return ResponseResultUtils.getResponseResultF("请联系管理员添加二维码信息!");
        }
        merchantCollectionImage.setWx(image.getWx());
        merchantCollectionImage.setAlipay(image.getAlipay());
        merchantCollectionImageService.updateById(merchantCollectionImage);
        return ResponseResultUtils.getResponseResultS("修改成功");
    }

    @GetMapping("/merchantCollectionImage")
    @ApiOperation("跳转到积分管理页面")
    public ModelAndView toJifenguanli(HttpSession session){
        MerchantCollectionImage merchantCollectionImage = merchantCollectionImageService.getOne(new QueryWrapper<>());
        ModelAndView modelAndView = new ModelAndView("self/index_jifenguanli");
        modelAndView.addObject("usdtOnlinePay",merchantCollectionImage);
        return modelAndView;
    }


}
